package com.shawn.springboot.integeration.usermanager.controller;

import com.shawn.springboot.integeration.common.model.GenericResponse;
import com.shawn.springboot.integeration.usermanager.model.User;
import com.shawn.springboot.integeration.usermanager.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author shawn
 * @description: TODO
 * @date 2023/12/24
 */
@Api(tags = {"用户管理"})
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation(value = "新增用户", notes = "根据传入的数据，新增用户",
            produces = "application/json")
    @PostMapping("/add")
    public GenericResponse<User> addUser(@RequestBody User user) {
        userService.addUser(user);
        return GenericResponse.success(user);
    }

    @ApiOperation(value = "删除用户", notes = "根据传入的id，删除对应用户")
    @DeleteMapping("/delete/{id}")
    public GenericResponse<String> deleteUser(@PathVariable("id") String id) {
        userService.deleteById(id);
        return GenericResponse.success(id);
    }

    @ApiOperation(value = "修改用户", notes = "根据传入的数据，修改用户")
    @PutMapping("/update")
    public GenericResponse<User> updateUser(@RequestBody User user) {
        userService.updateUser(user);
        return GenericResponse.success(user);
    }

    @ApiOperation(value = "查询用户", notes = "根据传入的id，查找对应用户")
    @GetMapping("/query/{id}")
    public GenericResponse queryUser(@PathVariable("id") String id) {
        User user = userService.selectById(id);
        return GenericResponse.success(null);
    }
}
